<!--
 * @Description: 你的代码我的心
 * @Author: GGB
 * @Date: 2021-12-21 14:39:03
 * @LastEditors: GGB
 * @LastEditTime: 2021-12-30 14:42:44
-->
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <!-- <a-button type="primary" @click="handleCreate"> 新增角色 </a-button> -->
      </template>
      <template #img="{ record }">
        <TableImg :imgList="[record.goods_image]" :size="50" />
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: 'clarity:note-edit-line',
              label: '库存',
              onClick: handleEdit.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
    <Modal @register="registerModal" />
  </div>
</template>
<script lang="ts" setup>
import { BasicTable, useTable, TableAction, TableImg, FetchSetting } from '/@/components/Table';
import { getGoodsList } from '/@/api/goods';
import { columns, searchFormSchema } from './goods.data';
import Modal from './modal/Modal.vue';
import { useModal } from '/@/components/Modal';
const [registerModal, { openModal }] = useModal();
const [registerTable, { reload }] = useTable({
  title: '角色列表',
  api: getGoodsList,
  fetchSetting: {
    sizeField: 'list.per_page',
    // // 请求接口当前页数
    pageField: 'list.current_page',
    // 请求结果列表字段  支持 a.b.c
    listField: 'list.data',
    // 请求结果总数字段  支持 a.b.c
    totalField: 'list.total',
  } as FetchSetting,
  columns,
  formConfig: {
    labelWidth: 120,
    schemas: searchFormSchema,
  },
  useSearchForm: true,
  showTableSetting: true,
  bordered: true,
  showIndexColumn: false,
  actionColumn: {
    width: 80,
    title: '操作',
    dataIndex: 'action',
    slots: { customRender: 'action' },
    fixed: undefined,
  },
});

const handleEdit = (record: Recordable) => {
  openModal(true, { record, reload });
};

const handleSuccess = () => {
  reload();
};
</script>
